package com.koicarp.university.graduate.service.service.information.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koicarp.university.graduate.service.dao.InformationTypeDao;
import com.koicarp.university.graduate.service.entity.information.InformationType;
import com.koicarp.university.graduate.service.service.information.IInformationTypeService;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 【资讯管理：资讯类别表】(InformationType)表服务实现类
 *
 * @author liutao
 * @since 2020-07-30 17:23:22
 */
@Service("informationTypeService")
public class InformationTypeServiceImpl extends ServiceImpl<InformationTypeDao,InformationType> implements IInformationTypeService {
    @Resource
    private InformationTypeDao informationTypeDao;

    @Override
    public UniversityResponse getAllType() {
        UniversityResponse response = new UniversityResponse();
        response.code(BaseConstant.RESPONSE_CODE_SUCCESS_200);
        response.message(BaseConstant.RESPONSE_MESSAGE_OPR_SUCCESS);
        List<InformationType> list = this.informationTypeDao.queryAll(new InformationType());
        if (list.size() > 0){
            response.data(list);
            return response;
        }
        response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
        response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        return response;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public InformationType queryById(Integer id) {
        return this.informationTypeDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<InformationType> queryAllByLimit(int offset, int limit) {
        return this.informationTypeDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param informationType 实例对象
     * @return 实例对象
     */
    @Override
    public InformationType insert(InformationType informationType) {
        this.informationTypeDao.insert(informationType);
        return informationType;
    }

    /**
     * 修改数据
     *
     * @param informationType 实例对象
     * @return 实例对象
     */
    @Override
    public InformationType update(InformationType informationType) {
        this.informationTypeDao.update(informationType);
        return this.queryById(informationType.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.informationTypeDao.deleteById(id) > 0;
    }
}